/*
 * Ganesa Copyright (C) 2008 Wim Crols <twimpiex@gnx.be>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License Version 3
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

package be.gnx.ganesa.application.command;

import java.util.Vector;

import be.gnx.ganesa.application.model.Application;
import be.gnx.ganesa.application.model.Cuboid;
import be.gnx.ganesa.application.model.Layer;
import be.gnx.ganesa.application.model.Project;
import be.gnx.ganesa.application.plugin.ImportPlugin;
import be.gnx.ganesa.application.ui.dialog.ImportDialog.ImportDialogResult;

public abstract class ImportCommand extends Command {

  protected ImportDialogResult importDialogResult;

  protected ImportPlugin importPlugin;

  public ImportCommand(Application application, ImportDialogResult importDialogResult, ImportPlugin importPlugin) {
    super(application);
    this.importDialogResult = importDialogResult;
    this.importPlugin = importPlugin;
  }

  @Override
  public void execute() {
    if ((application != null)
        && (application.getSelectedProject() != null)
        && (importDialogResult != null)
        && (importDialogResult.boundingBoxTabItemControl != null)
        && (importDialogResult.boundingBoxTabItemControl.getBoundingBox() != null)) {
      execute(application.getSelectedProject().newLayers(importPlugin, importDialogResult));
    }
  }

  protected Project getProject() {
    return application.getSelectedProject();
  }

  protected Cuboid getBoundingBox() {
    return importDialogResult.boundingBoxTabItemControl.getBoundingBox();
  }

  protected abstract void execute(Vector<Layer> layers);

}
